using System;

namespace FrameWork
{
    public abstract class ObjectBase : IReference
    {
        protected string _name;

        public string Name
        {
            get=> _name;
        }

        private object _target;
        public object Target { get { return _target; } }


        private DateTime _lastUseTime;
        public DateTime LastUseTime 
        {
            get => _lastUseTime;
            set => _lastUseTime = value;
        }

        public ObjectBase()
        {
            _name = null;
            _target = null;
            _lastUseTime = default(DateTime);
        }

        /// <summary>
        /// 初始化名字和目标
        /// </summary>
        protected void Init(string name,object target)
        {
            if(target == null)
            {
                throw new NullReferenceException($"the {name} target is null");
            }

            _name = name;
            _target = target;
            _lastUseTime = DateTime.UtcNow;
        }

        public void Clear()
        {
            _name = null;
            _target = null;
            _lastUseTime = default(DateTime);
        }

        protected internal abstract void OnSpawn();

        protected internal abstract void OnUnSpawn();

        protected internal abstract void Release();
    }
}

